package ink.lovejinhu.leetcode;

import java.util.ArrayList;
import java.util.HashSet;

/**
 * @author jinhu
 * created 2021-07-20 15:25
 */
public class Solution_0500 {
    public String[] findWords(String[] words) {
        String row1 = "qwertyuiop";
        String row2 = "asdfghjkl";
        String row3 = "zxcvbnm";
        HashSet<Character> row1c = new HashSet<>();
        HashSet<Character> row2c = new HashSet<>();
        HashSet<Character> row3c = new HashSet<>();
        ArrayList<String> res = new ArrayList<>();
        for (int i = 0; i < row1.length(); i++) {
            row1c.add(row1.charAt(i));
        }
        for (int i = 0; i < row2.length(); i++) {
            row2c.add(row2.charAt(i));
        }
        for (int i = 0; i < row3.length(); i++) {
            row3c.add(row3.charAt(i));
        }
        for (int i = 0; i < words.length; i++) {
            if (this.isBoolean(row1c, words[i].toLowerCase()) || this.isBoolean(row2c, words[i].toLowerCase()) || this.isBoolean(row3c, words[i].toLowerCase())) {
                res.add(words[i]);
            }
        }
        String[] ints = new String[res.size()];
        for (int i = 0; i < res.size(); i++) {
            ints[i] = res.get(i);
        }
        return ints;
    }

    public boolean isBoolean(HashSet<Character> characters, String words) {
        for (int i = 0; i < words.length(); i++) {
            if (!characters.contains(words.charAt(i))) {
                return false;
            }

        }
        return true;
    }

    public static void main(String[] args) {
        String row1 = "qwertyuiop";
        String row2 = "asdfghjkl";
        String row3 = "zxcvbnm";
        HashSet<Character> row1c = new HashSet<>();
        HashSet<Character> row2c = new HashSet<>();
        HashSet<Character> row3c = new HashSet<>();
        ArrayList<String> res = new ArrayList<>();
        for (int i = 0; i < row1.length(); i++) {
            row1c.add(row1.charAt(i));
        }
        for (int i = 0; i < row2.length(); i++) {
            row2c.add(row2.charAt(i));
        }
        for (int i = 0; i < row3.length(); i++) {
            row3c.add(row3.charAt(i));
        }
        Solution_0500 solution_0500 = new Solution_0500();
        boolean alaska = solution_0500.isBoolean(row3c, "b".toLowerCase());
        String[] temp = {"a", "b"};
        String[] words = solution_0500.findWords(temp);
        System.out.println(alaska);
        for (int i = 0; i < words.length; i++) {
            System.out.println(words[i]);

        }
    }
}
